package com.puboot.common.util;

import java.math.BigDecimal;
import java.util.List;

/**
 * 煤炭
 * Created by chen on 2021/12/26.
 */
public class CoalUtil {

    /**
     * 温室气体排放总量，单位为t
     * @param eBurn 化石燃料燃烧二氧化碳排放量，单位为t
     * @param ech4 甲烷逃逸排放量，单位为t
     * @param eco2 二氧化碳逃逸排放量，单位为t
     * @param ePurchaseElectric 购入电力对应的二氧化碳排放量，单位为t
     * @param ePurchaseHeat 购入热力对应的二氧化碳排放量，单位为t
     * @param eOutputElectric 输出电力对应二氧化碳排放量，单位为t
     * @param eOutputHeat 输出热力对应二氧化碳排放量，单位为t
     * @return
     */
    public static Double getE(Double eBurn, Double ech4, Double eco2, Double ePurchaseElectric,
                              Double ePurchaseHeat, Double eOutputElectric,
                              Double eOutputHeat) {
        BigDecimal eOutputElectricB = new BigDecimal(eOutputElectric);
        BigDecimal eOutputHeatB = new BigDecimal(eOutputHeat);
        BigDecimal jsgc1 = GasDCUtil.allAdd(eBurn, ech4, eco2, ePurchaseElectric, ePurchaseHeat);
        BigDecimal jsgc2 = jsgc1.subtract(eOutputElectricB);
        BigDecimal jsgc3 = jsgc2.subtract(eOutputHeatB);
        return jsgc3.doubleValue();
    }


    /**
     * 甲烷逃逸排放量，单位为t
     * @param adWellWorkers 矿井i当年的原煤产量，单位为t
     * @param qch4 矿井i当年的相对瓦斯涌出量，单位为m3/t
     * @param adOpenAirs 露天煤矿i当年的原煤产量，单位为t
     * @param adPostMines 瓦斯等级为i的所有矿井的原煤产量之和，单位为t
     * @param efPostMines 瓦斯等级为i的矿井的矿后活动甲烷排放因子，单位为m3/t
     * @param qGasTorch 煤层气（煤矿瓦斯）的火炬燃烧量及催化氧化量之和，单位为104m3
     * @param methaneCh4Torch 用于火炬燃烧或催化氧化的煤层气（煤矿瓦斯）中甲烷的平均体积分数，单位为%
     * @param qGasUtilize 煤层气（煤矿瓦斯）回收利用量，包括回收自用和回收外供的量（火炬燃烧和催化氧化除外），单位为104m3
     * @param methaneCh4Utilize 回收利用的煤层气（煤矿瓦斯）中甲烷的平均体积分数，单位为104m3
     * @return
     */
    public static Double getEch4(List<String> adWellWorkers, List<String> qch4, List<String> adOpenAirs, List<String> adPostMines,
                                 List<String> efPostMines, Double qGasTorch, Double methaneCh4Torch,
                                 Double qGasUtilize, Double methaneCh4Utilize){
        BigDecimal cl1B = new BigDecimal(140.7);
        BigDecimal result = new BigDecimal(0.0);
        BigDecimal jsgc1 = new BigDecimal(0.0);
        for (int i = 0; i < adWellWorkers.size(); i++) {
            BigDecimal jsgc = GasDCUtil.allMul(Double.valueOf(adWellWorkers.get(i)), Double.valueOf(qch4.get(i)), 0.0001);
            jsgc1 = jsgc1.add(jsgc);
        }
        result = result.add(jsgc1);
        BigDecimal jsgc2 = new BigDecimal(0.0);
        for (int i = 0; i < adOpenAirs.size(); i++) {
            BigDecimal jsgc = GasDCUtil.allMul(Double.valueOf(adOpenAirs.get(i)), 0.0002);
            jsgc2 = jsgc2.add(jsgc);
        }
        result = result.add(jsgc2);
        BigDecimal jsgc3 = new BigDecimal(0.0);
        for (int i = 0; i < adPostMines.size(); i++) {
            BigDecimal jsgc = GasDCUtil.allMul(Double.valueOf(adPostMines.get(i)), Double.valueOf(efPostMines.get(i)), 0.0001);
            jsgc3 = jsgc3.add(jsgc);
        }
        result = result.add(jsgc3);
        BigDecimal jsgc4 = GasDCUtil.allMul(qGasTorch, methaneCh4Torch, 0.98);
        BigDecimal jsgc5 =  GasDCUtil.allMul(qGasUtilize, methaneCh4Utilize);
        result = result.subtract(jsgc4);
        result = result.subtract(jsgc5);
        result = result.multiply(cl1B);
        return result.doubleValue();
    }

    /**
     * 二氧化碳逃逸排放量，单位为t
     * @param adWellWorkers 矿井i当年的原煤产量，单位为t
     * @param qco2s 矿井i当年的相对二氧化碳涌出量，单位为m3/t
     * @param cnns 煤层气（煤矿瓦斯）中组分n化学分子式中碳原子的数目
     * @param methaneNs 组分n的体积分数，单位为%
     * @return
     */
    public static Double getEco2(List<String> adWellWorkers, List<String> qco2s, List<String> cnns, List<String> methaneNs, Double qGasTorch){
        BigDecimal cl1 = new BigDecimal(22.4);
        BigDecimal cl2 = new BigDecimal(12);
        BigDecimal jsgc1 = new BigDecimal(0.0);
        for (int i = 0; i < adWellWorkers.size(); i++) {
            BigDecimal jsgc = GasDCUtil.allMul(Double.valueOf(adWellWorkers.get(i)), Double.valueOf(qco2s.get(i)), 0.0001);
            jsgc1 = jsgc1.add(jsgc);
        }
        jsgc1 = GasDCUtil.allMul(jsgc1.doubleValue(), 18.4);
        BigDecimal jsgc2 = new BigDecimal(0.0);
        for (int i = 0; i < cnns.size(); i++) {
            BigDecimal jsgc = GasDCUtil.allMul(Double.valueOf(cnns.get(i)), Double.valueOf(methaneNs.get(i)), 120.0);
            jsgc = jsgc.divide(cl1, 10, BigDecimal.ROUND_HALF_UP);
            jsgc2 = jsgc2.add(jsgc);
        }
        jsgc2 = GasDCUtil.allMul(jsgc2.doubleValue(), qGasTorch, 43.12);
        jsgc2 = jsgc2.divide(cl2, 10, BigDecimal.ROUND_HALF_UP);
        return jsgc1.add(jsgc2).doubleValue();
    }

}
